package com.hfi.chainofresponsibility.demo01;

/**
 * @author ChangLiang
 * @date 2020/4/14
 */
public abstract class AbstractHelpHandler implements HelpHandler {

    HelpHandler nextHelpHandler;

    String helpInfo;

    boolean hasHelp = false;

    @Override
    public void setHasHelp(boolean hasHelp){
        this.hasHelp = hasHelp;
    }

    @Override
    public void setNext(HelpHandler next) {
        this.nextHelpHandler = next;
    }

    @Override
    public void process() {
        if (hasHelp()) {
            // show help info
            HelpMessageSingleton.getInstance().setHelpMessage(helpInfo);
        } else {
            if (nextHelpHandler != null) {
                nextHelpHandler.process();
            }
        }
    }

    @Override
    public void setHelpInfo(String str) {
        helpInfo = str;
    }

    @Override
    public boolean hasHelp() {
        return hasHelp;
    }
}
